﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Bear.Library.Util
{
    public class SerializerHelper
    {
        public static void XmlSerializer(object obj, string path)
        {
            XmlSerializer se = new XmlSerializer(obj.GetType());
            using (StreamWriter sw = new StreamWriter(path))
            {
                se.Serialize(sw, obj);
            }
        }

        public static T XmlDeserialize<T>(string path)
        {
            XmlSerializer se = new XmlSerializer(typeof(T));
            using (StreamReader sr = new StreamReader(path))
            {
                return (T)se.Deserialize(sr);
            }
        }


    }
}
